local extension = Package:new("zhong")
extension.extensionName = "ats"

Fk:loadTranslationTable{
    ["zhong"] = "终",
}

local xiongye = fk.CreateTriggerSkill{
  name = "xiongye",
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  priority = -1,
  derived_piles = "xiongye_pile",
  events = {fk.DamageCaused},
  can_trigger = function(self, event, target, player, data)
    if data.from == player then
      return player:hasSkill(self) and data.to ~= player
    elseif data.to == player then
      return player:hasSkill(self) and data.from ~= player and data.from ~= nil
    end
    return false
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local drawNum = data.damage * 3
    local cards = room:getNCards(drawNum)
    player:addToPile("xiongye_pile", cards, true, self.name)
  end,
}
local xiongye_view = fk.CreateViewAsSkill{
  name = "xiongye_view",
  anim_type = "support",
  pattern = "slash,peach,analeptic,nullification",  
  expand_pile = "xiongye_pile",
  card_filter = function(self, to_select, selected)
    if #selected > 0 then return false end
    local player = Self
    if not player then return false end
    local pile = player:getPile("xiongye_pile")
    if not pile then return false end
    local card = Fk:getCardById(to_select)  
    if not card then return false end
    local handler = ClientInstance.current_request_handler
    if not handler then return false end
    if handler.pattern and not card:matchPattern(handler.pattern) then
      return false
    end
    if handler.class.name == "ReqUseCard" and player:prohibitUse(card) then
      return false
    end
    if handler.class.name == "ReqResponseCard" and player:prohibitResponse(card) then
      return false
    end
    if player:prohibitUse(card) and player:prohibitResponse(card) then
      return false
    end
    return table.contains(pile, to_select)
  end,

  view_as = function(self, cards)
    if #cards ~= 1 then return nil end
    local card = Fk:getCardById(cards[1])
    if not card then return nil end
    local newCard = Fk:cloneCard(card.name)
    newCard:addSubcard(card)
    newCard.skillName = self.name
    return newCard
  end,
}

local aojie = fk.CreateProhibitSkill{
    name = "aojie",
    frequency = Skill.Compulsory,
    prohibit_use = function(self, player, card)
      return card.name == "jink" and player:hasSkill(self)
    end,
    prohibit_response = function(self, player, card)
      return card.name == "jink" and player:hasSkill(self)
    end,
}

xiongye:addRelatedSkill(xiongye_view)

local anpeila = General:new(extension, "zhong_anpeila", "yv", 4)
anpeila:addSkill(xiongye)
anpeila:addSkill(aojie)

Fk:loadTranslationTable{
    ["zhong_anpeila"] = "安培拉",
    ["#zhong_anpeila"] = "黑暗皇帝",
    ["designer:zhong_anpeila"] = "子右",    --设计者
    ["cv:zhong_anpeila"] = "官方",          --配音
    ["illustrator:zhong_anpeila"] = "官方", --画师
    ["xiongye"] = "雄野",
    [":xiongye"] = "锁定技，当你对其他角色造成一点伤害时，或其他角色对你造成一点伤害时，你摸三张牌，然后将这些牌置于武将牌上，称为“野”。你可以将“野”当做手牌使用或打出",
    ["xiongye_pile"] = "野",
    ["xiongye_view"] = "雄野",
    [":xiongye_view"] = "你可以将“野”当做手牌使用或打出",
    ["aojie"] = "傲节",
    [":aojie"] = "锁定技，你不能使用或打出【闪】。",
    ["~anpeila"] = "朕，朕要变成光了..."
}

return extension